<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
import { browser, element, by, ExpectedConditions as ec } from 'protractor';

import { NavBarPage, SignInPage } from '../page-objects/jhi-page-objects';
<%_
let elementGetter = `getText()`;
if (enableTranslation) {
    elementGetter = `getAttribute('jhiTranslate')`;
} _%>

const expect = chai.expect;

describe('administration', () => {

    let navBarPage: NavBarPage;
    let signInPage: SignInPage;

    before(async () => {
        await browser.get('/');
        navBarPage = new NavBarPage(true);
        signInPage = await navBarPage.getSignInPage();
        <%_ if (authenticationType !== 'oauth2') { _%>
        await signInPage.autoSignInUsing('admin', 'admin');
        <%_ } else { _%>
        await signInPage.loginWithOAuth('admin', 'admin');
        <%_ } _%>
        await browser.wait(ec.visibilityOf(navBarPage.adminMenu), 5000);
    });

    beforeEach(async () => {
        await navBarPage.clickOnAdminMenu();
    });

    <%_ if (authenticationType !== 'oauth2') { _%>
    it('should load user management', async () => {
        await navBarPage.clickOnAdmin('user-management');
        <%_ if (enableTranslation) { _%>
        const expect1 = 'userManagement.home.title';
        <%_ } else { _%>
        const expect1 = 'Users';
        <%_ } _%>
        const value1 = await element(by.id('user-management-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });
    <%_ } _%>

    it('should load metrics', async () => {
        await navBarPage.clickOnAdmin('<%= jhiPrefixDashed %>-metrics');
        <%_ if (enableTranslation) { _%>
        const expect1 = 'metrics.title';
        <%_ } else { _%>
        const expect1 = 'Application Metrics';
        <%_ } _%>
        const value1 = await element(by.id('metrics-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });

    it('should load health', async () => {
        await navBarPage.clickOnAdmin('<%= jhiPrefixDashed %>-health');
        <%_ if (enableTranslation) { _%>
        const expect1 = 'health.title';
        <%_ } else { _%>
        const expect1 = 'Health Checks';
        <%_ } _%>
        const value1 = await element(by.id('health-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });

    it('should load configuration', async () => {
        await navBarPage.clickOnAdmin('<%= jhiPrefixDashed %>-configuration');
        await browser.sleep(500);
        <%_ if (enableTranslation) { _%>
        const expect1 = 'configuration.title';
        <%_ } else { _%>
        const expect1 = 'Configuration';
        <%_ } _%>
        const value1 = await element(by.id('configuration-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });

<%_ if (databaseType !== 'no' && databaseType !== 'cassandra') { _%>
    it('should load audits', async () => {
        await navBarPage.clickOnAdmin('audits');
        await browser.sleep(500);
        <%_ if (enableTranslation) { _%>
        const expect1 = 'audits.title';
        <%_ } else { _%>
        const expect1 = 'Audits';
        <%_ } _%>
        const value1 = await element(by.id('audits-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });

<%_ } _%>
    it('should load logs', async () => {
        await navBarPage.clickOnAdmin('logs');
        await browser.sleep(500);
        <%_ if (enableTranslation) { _%>
        const expect1 = 'logs.title';
        <%_ } else { _%>
        const expect1 = 'Logs';
        <%_ } _%>
        const value1 = await element(by.id('logs-page-heading')).<%- elementGetter %>;
        expect(value1).to.eq(expect1);
    });

    after(async () => {
        await navBarPage.autoSignOut();
    });
});
